package com.kaibes.module.token.core;

import java.time.LocalDateTime;

import com.kaibes.module.token.pojo.Token;
import com.kaibes.module.token.pojo.TokenType;

public class TokenBuilder {
    
    private Integer userId;
    private int minutes;
    private String aesKey;
    private String aesIv;
    
    public TokenBuilder setUserId(Integer userId) {
        this.userId = userId;
        return this;
    }
    
    public TokenBuilder setMinutes(int minutes) {
        this.minutes = minutes;
        return this;
    }
    
    public TokenBuilder setAesKey(String aesKey) {
        this.aesKey = aesKey;
        return this;
    }
    
    public TokenBuilder setAesIv(String aesIv) {
        this.aesIv = aesIv;
        return this;
    }
    
    public Token build(TokenType type) {
        Token token = new Token();
        token.setUserId(userId);
        token.setAesKey(aesKey);
        token.setAesIv(aesIv);
        token.setType(type);
        token.setCreateTime(LocalDateTime.now());
        token.setExpiration(token.getCreateTime().plusMinutes(minutes));
        return token;
    }
    
    public static TokenBuilder newBuilder() {
        return new TokenBuilder();
    }
    
}
